package com.sdtele.tta.operation;


import java.util.ArrayList;
import java.util.List;

import javax.swing.text.html.HTMLDocument.Iterator;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.sdtele.tta.dac.Dac;
import com.sdtele.tta.models.JsonRequest;
import com.sdtele.tta.models.JsonResponse;
import com.sdtele.tta.models.User;
import com.sdtele.tta.models.VoteOption;
import com.sdtele.tta.models.VoteTask;

public class OperationGetVoteOption extends Operation {
	
	public JsonResponse handle(JsonRequest jsonRequest) {
		System.out.println("OperationLogin:req="+jsonRequest);
		JsonResponse jres = new JsonResponse();
		long voteId = jsonRequest.getJsonObject().get("voteId").getAsLong();
		User curUser = (User) request.getSession().getAttribute("user");
		//获取请求中携带的voteid
		if (curUser!=null) {
			VoteTask voteTask = Dac.getInstance().getVoteTaskbyVoteid(voteId);
			
			if (curUser.getId() == voteTask.getOwnerId()) {
				List<VoteOption> voteOption=Dac.getInstance().getVoteOption(voteId);
				if ( voteOption.size()>0) {
				    
					jres.setStatus(0);
					jres.setMessage("获取投票选项成功");
					jres.setEntity(voteOption);
					return jres;
				}else {
					jres.setStatus(1);
					jres.setMessage("获取投票选项失败");
					return jres;
				}
			} else {
				jres.setStatus(1);
				jres.setMessage("您没有权限删除此投票任务");
			}
		} else {
			jres.setStatus(1);
			jres.setMessage("用户未登录");
		}
		return jres;
	}
}
	